package com.example.demo.dao.system;

import com.example.demo.model.system.Dict;
import com.example.demo.model.system.Role;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DictDAO {

//    一对一 employee_id
    @Select("select * from dict where dict_id=#{employee_id} and super_id=1")
    List<Dict> getByEmployeeId(Integer employee_id);

//    一对一 product_model
    @Select("select * from dict where dict_id=#{product_model} and super_id=2")
    List<Dict> getByDictModelId(Integer product_model);

    //    一对一 product_unit
    @Select("select * from dict where dict_id=#{product_unit} and super_id=3")
    List<Dict> getByDictUnitId(Integer product_unit);


//    部门下拉列表
    @Select("select * from dict where super_id=#{super_id}")
    public List<Dict> selectBySuperId(Integer super_id);

    @Select("select * from dict")
    public List<Dict> selectAll();

    @Insert("insert into dict(title,code,super_id)values(#{title},#{code},#{super_id})")
    Integer addDict(Dict dict);

    @Delete("delete from dict where dict_id=#{dict_id}")
    Integer deleteById(Integer dict_id);

    @Update("update dict set title=#{title},code=#{code},super_id=#{super_id} where dict_id=#{dict_id} ")
    Integer updateById(Dict dict);


//    模糊查询
@Select("<script>"+
        "select * from dict " +
        "<where>"+
        "<if test=\"title !=null and title != ''\">"+
        "and title like CONCAT('%',#{title},'%')"+
        "</if>"+
        "<if test=\"code !=null and code != ''\">"+
        "and code like CONCAT('%',#{code},'%')"+
        "</if>"+
        "<if test=\"super_id !=null and super_id != ''\">"+
        "and super_id like CONCAT('%',#{super_id},'%')"+
        "</if>"+
        "</where>"+
        "</script>")
public List<Dict> findDict(String  title,String code,Integer super_id) ;

}
